/*
 *   The contents of this file are subject to the Mozilla Public License
 *   Version 1.1 (the "License"); you may not use this file except in
 *   compliance with the License. You may obtain a copy of the License at
 *   http://www.mozilla.org/MPL/
 *
 *   Software distributed under the License is distributed on an "AS IS"
 *   basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 *   License for the specific language governing rights and limitations
 *   under the License.
 *
 *   The Original Code is OkkamNGClient, in the package org.okkam.client.*.
 *
 *   The Initial Developer of the Original Code is 
 *		Heiko Stoermer (http://disi.unitn.it/~stoermer).
 *
 *   Portions created by the Initial Developer are Copyright (C) 2007
 *   the Initial Developer. All Rights Reserved.
 *
 *   Contributor(s): Daniel Giacomuzzi (etadaniel@gmail.com).
 *
*/
package org.okkam.client.test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.rmi.RemoteException;

import org.okkam.webservice.*;
import org.okkam.core.api.data.*;

/**
 * This test is bypassing SearchNGClient to pass directly an XML string to the web service.
 * @author stoermer
 *
 */
public class ClientTestXml {

	/**
	 * 
	 * @param args
	 */
	private static OkkamURIResult res;
	public static void main(String[] args){

		
		System.out.println("pwd: " + System.getProperty("user.dir"));
		String annotatedQueryString = "";
		try
		{
			FileInputStream fis = new FileInputStream(new File(System.getProperty("user.dir") + "/src/org/okkam/client/test/" + "annotated_query_ex2.xml"));
			int x= fis.available();
			byte b[]= new byte[x];
			fis.read(b);
			annotatedQueryString = new String(b);
		}	
		catch(IOException e)
		{
			System.out.println(e.getMessage());
			System.exit(0);
		}
		
		SearchNGProxy search = new SearchNGProxy();
		
		try
		{
			//search.setEndpoint("http://okkam.dit.unitn.it:8081/OkkamNGWebServices/services/SearchNG");
			//search.setEndpoint(new SearchNGServiceLocator().getSearchNGAddress());
			res = search.search(annotatedQueryString);
		}	
		catch (RemoteException e)
		{
			System.out.println("Remote Exception: " + e.getMessage());
			e.printStackTrace();
		}
		
		if(res != null)
		{
			System.out.println("Code: " + res.getCode());
			System.out.println("Message: " + res.getMessage());
			if(res.getCode() == 0)
			{
				String [] uris = res.getResult();
				for (int i = 0; i < uris.length; ++i)
				{
					System.out.println("URI_"+i+": "+uris[i]);
				}
			}
		}

	}

}
